package com.xc.h05.controller.wutao;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Consultlevel;
import com.xc.h05.service.wutao.ConsultLevelService2;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/consultlevel2")
public class ConsultLevelController2 {
    @Autowired
    private ConsultLevelService2 consultLevelService2;
    @GetMapping("/findAll")
    public List<Consultlevel> findAll(){
        return consultLevelService2.findAll();
    }

    @PostMapping("/add")
    public R add(@RequestBody Consultlevel consultlevel) {
        int add = consultLevelService2.add(consultlevel);
        if (add != 0) {
            return R.ok(consultlevel);
        } else {
            return R.fail("添加失败");
        }
    }
    @DeleteMapping("/delete")
    public int delete(Long id){
        return consultLevelService2.delete(id);
    }

    @PutMapping("/update")
    public int update(@RequestBody Consultlevel consultlevel){
        return consultLevelService2.update(consultlevel);
    }

//    分页查询所有
    @GetMapping("/getAll")
    public R getAll(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
            Consultlevel consultlevel
    ) {
        PageInfo<Consultlevel> pageInfo = consultLevelService2.findByPage(pageNum, pageSize,consultlevel);
        return R.ok(pageInfo);
    }
//    根据id批量删除
    @PostMapping("/deletelevelByIds")
    public R deletelevelByIds(@RequestBody java.util.List<Long> ids2) {
        int i = consultLevelService2.deletelevelByIds(ids2);
        if (i >= 0) {
            return R.ok("批量删除成功");
        }else return R.fail ("批量删除失败");
    }
    //根据id查询
    @GetMapping("/findById")
    public Consultlevel findById(Integer id){
        Consultlevel consultlevel = consultLevelService2.findById(id);
        return consultlevel;
    }
}
